<?php
require_once 'libraries/functions.php';
echo "Sua thong tin: " . "<br>";
$path = "../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);
$films = mreadFile($path);
?>
<form method="POST">
    <?php
    for ($i = 0; $i < count($films); $i++) {
        $a = trim($films[$i], "\t\n\r");
        $film = explode(";", $a);
        if ($_GET["if"] == $film[0]) {
            ?>
            <table>
                <tr>
                <img src = '../ptnhuan-web1/public/images/films/<?php echo $film[1] ?>'>
                </tr>
                <tr>
                    <td>Ten :</td>
                    <td><input type='text' name='name' size='80'value="<?php echo $film[2] ?>"></td>
                </tr>            
                <tr>
                    <td>Rating :</td>
                    <td><input type='text' name='rating' size='80' value="<?php echo $film[3] ?>"></td>
                </tr>
            </table>
            <p><input type='submit' name="submit" value='Sua'></p>
            <?php echo '<a href="file.php">Bam vao day de quay lai<br></a>'; ?>
            <?php
        }
    }
?>
</form>

<?php
if (isset($_POST["submit"])) {
    for ($i = 0; $i < count($films); $i++) {
        $edit = trim($films[$i], " \t\n\r");
        if (!empty($edit)) {
            $films[$i] = explode(";", $edit);
            if ($_GET["if"] == $films[$i][0]) {
                $films[$i][2] = $_POST["name"];
                $films[$i][3] = $_POST["rating"];
            }
        } else {
            $films[$i] = $edit;
        }
    }
    edit($films);
}
?>